﻿using InnovaApp.Layers.DataLayer;
using InnovaApp.Portals.MVC4Portal.Models.JSonModels;
using InnovaApp.Portals.MVC4Portal.Models.WebAPIModels.JSTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Security;

namespace InnovaApp.Portals.MVC4Portal.Controllers.WebAPIControllers.UserRegistration
{
    /// <summary>
    /// Class CheckUserNameAvailabilityController.
    /// </summary>
    public class CheckUserNameAvailabilityController : _WebAPIControllers_Base<CheckUserNameAvailability_WebAPIModel>
    {
        protected static string eMethodBase = "InnovaApp.Portals.MVC4Portal.Controllers.WebAPIControllers.UserRegistration.CheckUserNameAvailabilityController";

        /// <summary>
        /// HTTP Post
        /// </summary>
        /// <param name="language">The language.</param>
        /// <param name="model">The model.</param>
        /// <returns>HttpResponseMessage.</returns>
        public HttpResponseMessage Post(string language, CheckUserNameAvailability_JSonModel model)
        {
            HttpResponseMessage toReturn;
            string eMethod = eMethodBase + ".Post";
            object eParameters = new { language = language, model = model};
            MembershipUser checkedUser = Membership.GetUser(model.username);
            ApiData.success = true;
            ApiData.isAvailable = checkedUser == null;
            toReturn = base.CreateResponse(HttpStatusCode.OK);
            return toReturn;            
        }
    }
}
